package Presentation.GraphicUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.DateFormat;

public class AddNewRecommendationScreen extends MovieSystemPanel
{

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;
    private JComboBox movies;
    final JComboBox rank = new JComboBox();
    
    public AddNewRecommendationScreen(final MainScreen mainScreen)
	{
		super(mainScreen);
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

        movies = new JComboBox();

        for(int i=0;i<10;i++)
            rank.addItem(i+1);

		final JTextArea recommendation = new JTextArea(10, 15);
		JLabel movieLabel = new JLabel("Movie name: ");
		JLabel rankLabel = new JLabel("Rank: ");
		JLabel recLabel = new JLabel("Description: ");

		JPanel j = new JPanel(new FlowLayout(FlowLayout.LEFT));
		j.add(movieLabel);
		j.add(movies);
        add(j);

        j = new JPanel(new FlowLayout(FlowLayout.LEFT));
        j.add(rankLabel);
		j.add(rank);
        add(j);

        j = new JPanel(new FlowLayout(FlowLayout.LEFT));
        j.add(recLabel);
		j.add(recommendation);
		add(j);

        j = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		setVisible(true);
		JButton button1 = new JButton("Save");
		
		button1.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
                if (movies.getSelectedIndex() == 0){
                    JOptionPane.showMessageDialog(mainScreen,"Please choose a movie");
                    return;
                }
                try
				{
					m_controller.addMovieRecommendation((String)movies.getSelectedItem(), rank.getSelectedIndex(),recommendation.getText());
					JOptionPane.showMessageDialog(mainScreen, "Your recommandation saved succesfully");
                    m_mainScreen.setActivePanel(MainScreen.MAIN_MENU);                    
				}
				catch (Exception e2) 
				{
					JOptionPane.showMessageDialog(mainScreen, e2.getMessage());
				}
            }
		});
			
		j.add(button1);
		add(j);
	}

    public void setUp(){
        movies.removeAllItems();
        movies.addItem("Choose movie...");
        for(String movie: m_controller.getUnrecomendedUserMovies())
            movies.addItem(movie);
        movies.setSelectedIndex(0);
        rank.setSelectedItem(10);
    }
}
